package com.kaibai.dao.impl;

import com.kaibai.dao.BaseDao;
import com.kaibai.dao.OrderDao;
import com.kaibai.pojo.Order;

import java.sql.Connection;
import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Connection conn,Order order) {
        String sql = "insert into t_order(order_id , create_time , price, status , user_id) values(?,?,?,?,?)";
        return update(conn,sql,order.getOrderid(),order.getCreateTime(),order.getPrice(),order.getStatus(),order.getUserId());
    }

    @Override
    public List<Order> queryOrders(Connection conn) {
        String sql = "select order_id as orderid,create_time as createTime,price,status,user_id as userId from t_order";
        return getForList(conn,Order.class,sql);
    }

    @Override
    public int changeOrderStatus(Connection conn, String orderId, Integer status) {
        String sql = "update t_order set status=?  where order_id=?";
        return update(conn,sql,status,orderId);
    }

    @Override
    public List<Order> queryOrdersByUserId(Connection conn, Integer userId) {
        String sql = "select order_id as orderid,create_time as createTime,price,status,user_id as userId from t_order where user_id=?";
        return getForList(conn,Order.class,sql,userId);
    }

}
